﻿using System.ComponentModel;

namespace Borg.Framework
{
    public abstract class ExtensionBase
    {
        private ExtensionInfo _extensionInfo;

        protected void LogEvent(LogEventArgs args)
        {
            Extension.LogEvent(args);
        }

        protected void LogEvent(MessageType type, string message, params object[] args)
        {
            Extension.LogEvent(new LogEventArgs(type, VerbosityLevel.Normal, message, args));
        }

        [Browsable(false)]
        public ExtensionInfo Extension
        {
            get { return _extensionInfo ?? (_extensionInfo = Runtime.GetExtensionInfo(this)); }
        }

        [Browsable(false)]
        public ExtensionTypeInfo ExtensionType
        {
            get { return Extension == null
                ? null
                : Extension.ExtensionTypeInfo; }
        }

        [Browsable(false)]
        public PluginInfo Plugin
        {
            get { return Extension == null
                ? null
                : Extension.ExtensionTypeInfo.PluginInfo; }
        }

        [Browsable(false)]
        public RepositoryCollection<PlugInfo> Plugs
        {
            get { return Extension == null
                ? null
                : Extension.PlugInfos; }
        }

        [Browsable(false)]
        public RepositoryCollection<PlugTypeInfo> PlugTypes
        {
            get { return Extension == null
                ? null
                : Extension.ExtensionTypeInfo.PlugTypeInfos; }
        }

        [Browsable(false)]
        public RepositoryCollection<SlotInfo> Slots
        {
            get { return Extension == null
                ? null
                : Extension.SlotInfos; }
        }

        [Browsable(false)]
        public RepositoryCollection<SlotTypeInfo> SlotTypes
        {
            get { return Extension == null
                ? null
                : Extension.ExtensionTypeInfo.SlotTypeInfos; }
        }
    }
}

